<?php
namespace Admin\Controller;
use Think\Controller;
class CommonController extends Controller{
	/*初始化
	* 构造函数
	*/
    public function _initialize(){
		
		 $rule = array('login'=>array('login','lgout','verify','check_verify'));//不需要登录操作的类对于的方法
		 $url = array_key_exists(strtolower(CONTROLLER_NAME),$rule);
		
		if (!session('admin_id') && !$url) {	
		
			 $this->redirect('login/login','请先登录！');
			 
		} else{
						
			if (!$url) {
				
				if (!$_SESSION['gr_status']) {
					die('<script>alert("您没有操作权限");history.go(-1);</script>');
				}
				
				S('urlset',null);
				unset($data);
				//超时强制退出
				$timeover = timeOver();
				
				if (!$timeover) {					
					$this->redirect('login/login','登录超时，请重新登录！');
				}
				
				$url_str = explode('/',$_SERVER['PATH_INFO']);
				$PATH_INFO = $url_str[0].'/'.$url_str[1];
				
				$where ['set_url'] = $PATH_INFO;
				$setone = _getOne('urlset',$where,'',0,$PATH_INFO);
				
				if ($setone['set_pid']>0) {
					$where2 ['set_id'] = $setone['set_pid'];
					$cache = 'seturl'.$setone['set_pid'];				
					$seturl = _getOne('urlset',$where2,'',0,$cache);
					
				} else{
					$seturl = $setone ;
				}
				
				//强制刷新
				_Refresh($_GET['clear'],'admmenu');
				//菜单导航
				$admmenu = menuParent();
				
				//子级菜单导航		
				if(!$setone['set_pid']) {
					$pid = $setone['set_id'];
				} else {
					$pid = $setone['set_pid'];
				}				
				$cache2 = 'setlist'.$pid;// 获取缓存数据 
				S($cache2,null);
				$menuSon = menuSon($pid,'urlset',$cache2,'set_id asc');	
				
				//手机端
				if (stripos($_SERVER['HTTP_USER_AGENT'],"android")!=false||stripos($_SERVER['HTTP_USER_AGENT'],"ios")!=false||stripos($_SERVER['HTTP_USER_AGENT'],"wp")!=false||stripos($_SERVER['HTTP_USER_AGENT'],"os")!=false) {
					$this->assign('wap',1);
				}
				
				if ($_SESSION['gr_status']!='2') {
					unset($set_U) ;
					$set_U = M('admingroup')->where('id=%d',array($_SESSION['gid']))->field('rules')->find();
					$is_ok = 0 ;
					if ($set_U) {
						$set_uL = unserialize ($set_U['rules']) ;
						foreach ($set_uL as $key=>$v) {
							if (strtolower($v)===strtolower($PATH_INFO)) {
								$is_ok = 1 ;
							}
						}
					}					
				} else {
					$is_ok = 1 ;
				}
				
				//dump($set_uL);die;
				$this->assign('is_ok',$is_ok);
				$this->assign('gr_status',$_SESSION['gr_status']);
				$this->assign('menuSon',$menuSon);
				$this->assign('admmenu',$admmenu);
				$this->assign('admin_name',$_SESSION['admin_unme']);
				$this->assign('pidurl',$seturl['set_url']);
				$this->assign('PATH_INFO',$PATH_INFO);				
			}
				
		}
		
    }

}